# Maintainer: Alexey Pavlov <alexpux@gmail.com>

pkgname=patch
pkgver=2.7.5
pkgrel=1
pkgdesc="A utility to apply patch files to original sources"
arch=('i686' 'x86_64')
url="http://www.gnu.org/software/patch/patch.html"
license=('GPL')
groups=('base-devel')
depends=('msys2-runtime')
makedepends=('ed')
optdepends=('ed: for patch -e functionality')
source=(ftp://ftp.gnu.org/gnu/${pkgname}/${pkgname}-${pkgver}.tar.xz{,.sig}
        msys2-patch-2.7.1.patch
        msys2-patch-manifest.patch)
md5sums=('e3da7940431633fb65a01b91d3b7a27a'
         'SKIP'
         'd1c8f6adf70068b0e17ed70a6ee21e1a'
         '29d502fa7ecb0845ca809dff9a29ad73')

prepare() {
  cd ${srcdir}/${pkgname}-${pkgver}

  patch -Np1 -i $srcdir/msys2-patch-2.7.1.patch
  patch -Np2 -i $srcdir/msys2-patch-manifest.patch

  local _arch=
  if [ "${CARCH}" == 'x86_64' ]; then
    _arch='amd64'
  elif [ "${CARCH}" == 'i686' ]; then
    _arch='x86'
  fi
  sed -e "s|@ARCH@|${_arch}|g" -i src/patch.manifest
  autoreconf -fi
}

build() {
  cd ${srcdir}/${pkgname}-${pkgver}

  ./configure \
    --build=${CHOST} \
    --prefix=/usr \
    ac_cv_func_setmode_dos=yes

  make
}

check() {
  cd ${srcdir}/${pkgname}-${pkgver}
  make check
}

package() {
  cd ${srcdir}/${pkgname}-${pkgver}
  make DESTDIR=$pkgdir install
}
